package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.PartsType;



public interface PartsTypeRepository extends JpaRepository<PartsType, String> {
	/**
	  * 从PartsType表获取分组的下拉框选项
	  * @param group
	  * @return
	  */
//	 @Query("select o from PartsType o where o.group = ?1 and o.title !='大型活动' and o.title !='大型活动安全防范' order by o.createTime asc")
//	 List<PartsType> findByGroup(String group);
	 /**
	  * 从PartsType表获取分组的下拉框选项
	  * @param group
	  * @return 返回String 集合
	  */
//	 @Query("select o.title from PartsType o where o.group = ?1 order by o.createTime asc")
//	 List<String> findPartsTypeByGroup(String group)
	 
	 /**
	  * 从PartsType表通过获取分组和标题获取下拉框选项
	  * @param group
	  * @return
	  */
//	 @Query("select o from PartsType o where o.group = ?1 and o.title = ?2 order by o.createTime asc")
//	 List<PartsType> findByGroupAndTitle(String group, String title);
	 

	 /**
	 * @param key
	 * @param pageable
	 * @return 得到选项配置PartsType的page，关键字为key
	 */
	@Query(" select o from PartsType o where o.parts_name like %?1% or o.parts_type like %?1% order by o.parts_type")
	 Page<PartsType> findPartsType(String key, Pageable pageable);
	
	/**
	 *
	 */
	@Query(" select o from PartsType o where o.parts_name like %?1% or o.parts_type like %?1% order by o.parts_type")
	List<PartsType> findAllPartsType(String key);
	 /**
	 * @param key
	 * @return 得到选项配置PartsType的条数，关键字为key
	 */
	@Query(" select count(*) as num from PartsType o where o.parts_name like %?1% or o.parts_type like %?1% ")
	 Long getPartsTypeCount(String key);
	
	@Query(" select o from PartsType o where o.parts_type = ?1 ")
	PartsType findPartsTypeByPartType(String parts_type);
}
